/*
  собственно, веб-страница



*/
#include "t_advWebPage.h"

t_advWebPage::t_advWebPage(QObject* parent)
        : QWebPage(parent)
{
    connect(this->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
            this, SLOT(populateJavaScriptWindowObject()));
}

//=================================================================
bool t_advWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type)
    {
        Navigation n;
        n.frame = frame;
        n.request = request;
        n.type = type;
        navigations.append(n);
        if (type == QWebPage::NavigationTypeOther)
            {
                //Сделано для того, чтобы QWebView реагировал на метод setUrl.
                return true;
            }
          else
            {
                emit this->urlClick(frame, request.url(), type);
                //return false;
            };
        return true;
    }

//будет использоваться только mainFrame() !!!!
//=================================================================
void t_advWebPage::evaluate(QString command)//запрос на выполнение команды из страницы
    {
        QWebFrame* frame = this->mainFrame();
        emit this->evaluate(frame, command);
    };

//будет использоваться только mainFrame() !!!!
//=================================================================
void t_advWebPage::reloadSection(QString sectionName)//запрос обновить часть страницы
    {
        QWebFrame* frame = this->mainFrame();
        emit this->reloadSection(frame, sectionName);
    };

//=================================================================
QWebPage* t_advWebPage::createWindow(QWebPage::WebWindowType _type)
    {
        QWebPage* page = new t_advWebPage(this);
        createdWindows.append(page);
        connect(page->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
                this, SLOT(populateJavaScriptWindowObject()));
        return page;
    }
//=================================================================
void t_advWebPage::populateJavaScriptWindowObject()
    {

             this->mainFrame()->addToJavaScriptWindowObject("pagebot", this);
    }
